package com.atguigu.func;

import com.atguigu.uitl.KeyWordUtil;
import org.apache.flink.table.annotation.DataTypeHint;
import org.apache.flink.table.annotation.FunctionHint;
import org.apache.flink.table.functions.TableFunction;
import org.apache.flink.types.Row;

import java.io.IOException;
import java.util.List;

/**
 * @author hjy
 * @create 2023/3/15 11:02
 */
@FunctionHint(output = @DataTypeHint("ROW<word STRING>"))
public  class SplitFunction extends TableFunction<Row> {

    public void eval(String keyword) {
        //collect(Row.of(s, s.length()));
        try {
            List<String> wordList = KeyWordUtil.getIkWord(keyword);
            for (String word : wordList) {
                collect(Row.of(word));
            }
        } catch (IOException e) {
            collect(Row.of(keyword));
        }
    }
}
